(*This file contains the procedures AlgMultInverse and AlgDivide.*)

AlgMultInverse[v_,p_,alpha_] := Module[
(*Mathematica implementation of Figure 4,5, page 151
This procedure requires the procedure: 

     ExtendedEuclideanAlgorithm (Figure 4.4, page 134, 
                                 requires additional procedures)
Input
  alpha : a symbol that represents an algebraic number
  p : a monic, irreducible polynomial in Q[alpha] with deg(p,alpha)>=2
  v : a non-zero polynomial in  Q(alpha) with deg(v) <  deg(p)
Output
  The multiplicative inverse of v in Q(alpha)

Local*)
  {w},
w = ExtendedEuclideanAlgorithm[v,p,alpha];
Return[Part[w,2]]
]

AlgDivide[u_,v_,p_,alpha_] := Module[
(*This procedure requires the procedures:

      AlgMultInverse (above, requires an additional procedure)
      Remainder (Figure 4.1, page 116) 

Input
  alpha : a symbol that represents an algebraic number
  p : a monic, irreducible polynomial in Q[alpha] with deg[p,alpha]>=2
  u,v : polynomials in  Q(alpha) with degree <  deg[p] and v =!= 0
Output
  The quotient of u divided by v in Q(alpha)
Local*) 
  {w},
w = AlgMultInverse[v,p,alpha];
Return[Remainder[Expand[u*w],p,alpha]]
]
